package com.jdk8;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;

public class CalculateAgeTest {
    /*
    计算用户年龄
     */
    public static void main(String[] args) {
        System.out.println("请输入生日：xxxx年xx月xx日");
        Scanner sc=new Scanner(System.in);
        String birthday=sc.nextLine();

        LocalDate birthdayDate=LocalDate.parse(birthday, DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
        LocalDate now=LocalDate.now();

        long result= ChronoUnit.YEARS.between(birthdayDate,now);

        System.out.println("年龄为"+result);
    }
}
